package physics;

import model.Player;
import model.World;

/** 
 * @author Friden
 */
public class PhysicsEngine {
	
	private static PhysicsEngine instance = null;
	private Thread thread;
	private boolean run = true;
	
	/**
	 * Starts the Engine.
	 * 
	 * @param updateInterval how many times per second it should update.
	 */
	public void start(final int updateInterval){
		thread = new Thread(new Runnable(){
			private World world = World.getInstance();
			int update = 0;
			public void run(){
				while(run == true){					
					for(Player player : world.getPlayers()){
						if(player != null){
//							SmurfDomainLogic.updateSmurfPosition(player.getSmurf());
						}
					}
					for(Player player : world.getPlayers()){
						if(player != null){
//							SmurfDomainLogic.doTileActions(player.getSmurf());
						}						
					}
					try {
						Thread.sleep(updateInterval);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		});
		thread.start();
	}
	
	public void stop(){
		this.run = false;
	}
	
	public static PhysicsEngine getInstance(){
		if(instance == null){	
			instance = new PhysicsEngine(); 
		}
		return instance;
	}
	
	private PhysicsEngine(){}
	
}
